package net.lab1024.sa.admin.module.business.lcy.student.contact.service;

import java.util.List;
import net.lab1024.sa.admin.module.business.lcy.student.contact.dao.LcyStudentContactDao;
import net.lab1024.sa.admin.module.business.lcy.student.contact.domain.entity.LcyStudentContactEntity;
import net.lab1024.sa.admin.module.business.lcy.student.contact.domain.form.LcyStudentContactAddForm;
import net.lab1024.sa.admin.module.business.lcy.student.contact.domain.form.LcyStudentContactQueryForm;
import net.lab1024.sa.admin.module.business.lcy.student.contact.domain.form.LcyStudentContactUpdateForm;
import net.lab1024.sa.admin.module.business.lcy.student.contact.domain.vo.LcyStudentContactVO;
import net.lab1024.sa.base.common.util.SmartBeanUtil;
import net.lab1024.sa.base.common.util.SmartPageUtil;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import net.lab1024.sa.base.common.domain.PageResult;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import jakarta.annotation.Resource;

/**
 * 联系人 Service
 *
 * @Author yangz
 * @Date 2025-10-31 19:00:52
 * @Copyright yangz
 */

@Service
public class LcyStudentContactService {

    @Resource
    private LcyStudentContactDao lcyStudentContactDao;

    /**
     * 分页查询
     */
    public PageResult<LcyStudentContactVO> queryPage(LcyStudentContactQueryForm queryForm) {
        Page<?> page = SmartPageUtil.convert2PageQuery(queryForm);
        List<LcyStudentContactVO> list = lcyStudentContactDao.queryPage(page, queryForm);
        return SmartPageUtil.convert2PageResult(page, list);
    }

    /**
     * 添加
     */
    public ResponseDTO<String> add(LcyStudentContactAddForm addForm) {
        LcyStudentContactEntity lcyStudentContactEntity = SmartBeanUtil.copy(addForm, LcyStudentContactEntity.class);
        lcyStudentContactDao.insert(lcyStudentContactEntity);
        return ResponseDTO.ok();
    }

    /**
     * 更新
     *
     */
    public ResponseDTO<String> update(LcyStudentContactUpdateForm updateForm) {
        LcyStudentContactEntity lcyStudentContactEntity = SmartBeanUtil.copy(updateForm, LcyStudentContactEntity.class);
        lcyStudentContactDao.updateById(lcyStudentContactEntity);
        return ResponseDTO.ok();
    }

    /**
     * 批量删除
     */
    public ResponseDTO<String> batchDelete(List<Long> idList) {
        if (CollectionUtils.isEmpty(idList)){
            return ResponseDTO.ok();
        }

        lcyStudentContactDao.deleteBatchIds(idList);
        return ResponseDTO.ok();
    }

    /**
     * 单个删除
     */
    public ResponseDTO<String> delete(Long contactId) {
        if (null == contactId){
            return ResponseDTO.ok();
        }

        lcyStudentContactDao.deleteById(contactId);
        return ResponseDTO.ok();
    }
}
